const fs = require("fs");
const path = require("path");
/**
 *
 * @param dirname 需要创建的目录
 * @returns
 */
export function mkdir(dirname: string) {
  if (fs.existsSync(dirname)) {
    return true;
  } else {
    if (mkdir(path.dirname(dirname))) {
      fs.mkdirSync(dirname);

      return true;
    }
  }
}
/**
 *
 * @returns 生成日期
 */
export function today() {
  let time = Date.parse(new Date() as any);
  let date = new Date(time);
  let Y = date.getFullYear() + "-";
  let M =
    (date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1) + "-";
  let D = date.getDate();
  return Y + M + D;
}
/**
 *
 * @param url 图片路径
 * @param name 图片名称
 * @returns
 */
export function slicePath(url: string, name: string) {
  let arr = name.split(".");
  let format = arr[arr.length - 1];
  return url.slice(-32) + "." + format;
}

/**
* 随机字符串
*/
export function createNonceStr() {
  return Math.random().toString(36).substr(2, 15);
};

/**
 * 时间戳
*/
export function createTimestamp() {
  return parseInt(String(new Date().getTime() / 1000)).toString();
};